package ll.j2ee;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.brickred.socialauth.AuthProvider;
import org.brickred.socialauth.AuthProviderFactory;

public class TestServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		response.setContentType("text/html");
		response.setStatus(response.SC_MOVED_TEMPORARILY);
		String id = "facebook";

		try 
		{ 
			AuthProvider provider = AuthProviderFactory.getInstance(id);	
			String returnToUrl = "http://opensource.brickred.com/socialauthdemo/socialAuthSuccessAction.do";
			System.out.println("Return URL..." + returnToUrl);
			String url = provider.getLoginRedirectURL(returnToUrl);	
			response.setHeader("Location", url);
		} 
			catch (Exception e)
		{ 
		  e.printStackTrace();
		} 

		PrintWriter out = response.getWriter();
		out.println("Tester ...");		
		System.out.println("--------------------");
	}
	
}
